﻿function loadMore(url, param, completecallback) {
    var maxId = $(".photo").last().attr("rel");
    var htmlTemplate = $(".row > div").first().html();
    param["maxid"] = maxId;
    $.getJSON(url, param, function (data) {
        if (completecallback) completecallback();

        $.each(data, function (index, item) {
            var photo = $('<div class="col-xs-12 col-md-2">' + htmlTemplate + '</div>');
            photo.find(".photo").attr("rel", item.Id);
            photo.find(".photo-user a").attr("href", "/Home/User/" + item.User.Id).text(item.User.UserName);
            photo.find(".photo-wrapper a").attr("href", "/Home/Media/" + item.Id).find("img").attr("src", item.Images.LowResolution.Url);
            var location = item.Location ? '<span class="glyphicon glyphicon-map-marker"></span>' : '';
            photo.find(".photo-title").empty().html(location + (item.Caption ? ("<span title='" + item.Caption.Text + "'>" + item.Caption.Text + "</span>") : ""));
            photo.find(".photo-mark").empty().html('<span class="glyphicon glyphicon-heart"></span>&nbsp;' + item.Likes.Count + ' &nbsp;<span class="glyphicon glyphicon-comment"></span>&nbsp;' + item.Comments.Count);
            photo.appendTo(".row");
        });
    });
}

function modifyRelation(url, param, onComplete) {
    $.post(url, param, function (data) {
        if (onComplete) onComplete();
    });
}